# -*- coding: utf-8 -*-

import maya.cmds as cmds
import maya.mel as mel
import os , sys
from Set_FlieName import Set_FlieName
# from Set_Path import Set_Path
from Check_CamName import Check_CamName
from Check_Export_Cam_FBX import Check_Export_Cam_FBX
from Check_Export_Cam_ABC import Check_Export_Cam_ABC
from Check_isLook_Cam import Check_isLook_Cam
from Check_isRefLoaded import Check_isRefLoaded
from Check_MergeAnim_layers import Check_MergeAnim_layers
from Check_TPose import Check_TPose
from Check_UnknownNode import Check_UnknownNode


class QL_batch_Check ( ) :
    def QL_batch_Check ( self ) :
        self.logs = ""
        current_file_pathlist = [ ]
        current_file_path = cmds.file ( query = True , sceneName = True )
        self.current_file_directory = os.path.dirname ( current_file_path )
        current_file_pathlist.append ( self.current_file_directory )
        if current_file_pathlist :
            file_folder = os.path.join ( self.current_file_directory , "Scence" ).replace ( "\\" , "/" )
            if not os.path.exists ( file_folder ) :
                os.mkdir ( file_folder )

            self.folder_path = os.path.join ( self.current_file_directory , "log" ).replace ( "\\" , "/" )
            if not os.path.exists ( self.folder_path ) :
                os.mkdir ( self.folder_path )

            camAbc_folder_path = os.path.join ( self.current_file_directory , "Cam_abc" ).replace ( "\\" , "/" )
            if not os.path.exists ( camAbc_folder_path ) :
                os.mkdir ( camAbc_folder_path )

            camFbx_folder_path = os.path.join ( self.current_file_directory , "Cam_fbx" ).replace ( "\\" , "/" )
            if not os.path.exists ( camFbx_folder_path ) :
                os.mkdir ( camFbx_folder_path )
            Flie_Name = str ( Set_FlieName ( ) )
            Check_MergeAnim_Log = ",动画层," + str ( Check_MergeAnim_layers ( ) )
            Check_isLook_Cam_Log = ",多余相机检查," + str ( Check_isLook_Cam ( ) )
            Check_CamName_Log = ",相机命名," + str ( Check_CamName ( ) )
            Check_Export_Cam_FBX_Log = ",cam_FBX导出," + str ( Check_Export_Cam_FBX ( ).Cam_Bake ( "_OUT" , camFbx_folder_path ) )
            Check_Export_Cam_ABC_Log = ",cam_ABC导出," + str ( Check_Export_Cam_ABC ( ).Cam_Bake ( "_OUT" , camAbc_folder_path ) )
            Check_UnknownNode_Log = ",未知节点," + str ( Check_UnknownNode ( ) )
            Check_isRefLoaded_Log = ",参考加载," + str ( Check_isRefLoaded ( ) )
            Check_TPose_Log = ",TPose," + str ( Check_TPose ( ).TPose_Run ( "Chr" ) )
            self.logs = Flie_Name + "\n" + Check_MergeAnim_Log + "\n" + Check_isLook_Cam_Log + "\n" + Check_CamName_Log + "\n" + Check_Export_Cam_FBX_Log + "\n" + Check_Export_Cam_ABC_Log + "\n" + Check_isRefLoaded_Log + "\n" + Check_TPose_Log + "\n" + Check_UnknownNode_Log + "\n"
            # 使用cmds.file命令保存为.ma格式文件
            try :
                cmds.file ( rename = os.path.join ( file_folder , Flie_Name + '.ma' ) )
                cmds.file ( save = True , type = 'mayaAscii' )
                self.logs += ",另存文件," + str ( "保存成功-YES" ) + "\n"
            except :
                self.logs += ",另存文件," + str ( "保存失败-NO" ) + "\n"
            Flie_Path = self.folder_path + "/log.txt"
            with open ( Flie_Path , 'a' ) as f :
                for line in self.logs.splitlines ( ) :
                    f.write ( line + "\n" )
        else :
            return (u"File name read failure!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")


QL_batch_Check ( ).QL_batch_Check ( )
